<?php
namespace app\common\model\user;

use think\Model;

class Setting extends Model
{
    protected $table = 'setting';
    protected $pk    = 'Id';


    // 获取参数
    public function getSetting($title) {

        $data = $this->where('title',$title)->find();
        return $data;
    }
    // 设置参数
    public function saveData($params) {
        // 查询参数是否存在
        $setting = $this->getSetting($params['title']);
        $rst = [];
        $t = time();
        if ($setting) {
            $setting->Content = $params['content'];
            $setting->UpdateTime = $t;
            $setting->save();
            $rst = [
                'UpdateTime' => $t
            ];
        } else {
            $this->Title = $params['title'];
            $this->Content = $params['content'];
            $this->CreateTime = $t;
            $this->UpdateTime = $t;
            $this->save();
            $rst = [
                'Id' => $this->Id,
            ];
        }
        return $rst;
    }
}
